# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
_pkgname=lyaml
pkgname=lua-$_pkgname
pkgver=6.2.8
pkgrel=1
pkgdesc="LibYAML binding for Lua"
url="https://github.com/gvvaughan/lyaml"
arch="all"
license="MIT"
makedepends="yaml-dev lua-stdlib-normalize"
replaces="lua-yaml"
source="$_pkgname-$pkgver.tar.gz::https://github.com/gvvaughan/lyaml/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"
options="!check"

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-$_pkgname:_subpackage"
done

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."

		cp -r "$builddir" "$srcdir"/build-$lver
		cd "$srcdir"/build-$lver
		lua$lver build-aux/luke
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname%-lyaml}"
	lver=${lver#lua}
	pkgdesc="$pkgdesc $lver"
	depends="lua$lver lua$lver-stdlib-normalize"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_pkgname/$pkgver-1"

	cd "$srcdir"/build-$lver

	lua$lver build-aux/luke PREFIX="$subpkgdir"/usr install
	rm -Rf "$subpkgdir"/usr/share/doc

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="
d9166d89f2275a1050218425c1365d6bda42294ab2629c71da3a2007eac7e8018e13d6e69181ea204eb7f051a49533e4b67227468b161df1f3450a073e2dbeab  lyaml-6.2.8.tar.gz
"
